package com.application.outdoor.InvoikeServices;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;

import android.util.Log;

import com.application.Network.Protocol;

public abstract class BaseInvoike {
	protected String url;
	public BaseInvoike(){
		url=Protocol.SERVER_URL;
	}
	protected  String post(String url,ArrayList<NameValuePair> params) throws Exception{
		//Log.i(Protocol.TAG,"post URL="+url);
		HttpClient client=new DefaultHttpClient();
		HttpPost post=new HttpPost(url);
		StringBuffer bf=new StringBuffer();
		
			
//			post.setHeader("Content-Type", "text/html; charset=UTF-8");
			post.setEntity(new UrlEncodedFormEntity(params,HTTP.UTF_8));
			HttpResponse response=client.execute(post);
			StatusLine status = response.getStatusLine();
			//Log.i(Protocol.TAG,"Status="+status.getStatusCode());
			if (status.getStatusCode() != 200) {
		          throw new Exception("Invalid response from server: " + status.toString());
		      }

			BufferedReader br=new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
			String line="";
			
			while((line=br.readLine())!=null){
				bf.append(line+'\n');
			}
		
		return bf.toString();
	}
}
